<?php
// 本类由系统自动生成，仅供测试用途
class InterfaceAction extends Action {

	
//http://localhost/dispatch/admin.php/Interface/getinfo/factory/Factory/project/67119486/line/PM1/shift/D/product/Product/number/100
    public function getinfo(){
    	header("Content-Type:text/html; charset=utf-8");
    	$item=D('Item');$line=D('Line');$plan=D('Plan');$ps=D('Ps');$part=D('Part');$yuzhi=D('Yuzhi');

        // logger('#','log/log_'.date('Y-m-d',time()).'.txt');
        // logger($_SERVER["REQUEST_SCHEME"].'://'.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"],'log/log_'.date('Y-m-d',time()).'.txt');

        $itemcode=gp()['project'];
        $arr_itemo=$item->getitemobyitemcode($itemcode);$itemo=$arr_itemo['data'];

        $linenm=gp()['line'];
        $arr_lineo=$line->getlineobylinenm($linenm);$lineo=$arr_lineo['data'];
        $linespeed=$lineo['linespeed'];//瓶/分
        $linespeed=$linespeed/$itemo['itemctn'];//箱/分


        
        //在现在运行的计划里头找到产线号和项目号对得上的，基本上就是
        $arr_plano=$plan->getplanobylineidanditemidandrunning($lineo['lineid'],$itemo['itemid']);$plano=$arr_plano['data'];

        if(!$plano){logger("该计划未找到",'log/log_'.date('Y-m-d',time()).'.txt');p(查找项目失败);die;}

        // //验证班次是否符合
        // $shift=gp()['shift'];if($shift=="D"){$shift=1;}else if($shift=="N"){$shift=2;}
        // if($shift!=$plano['f_plan_banciid']){
        //     logger("班次不对齐",'log/log_'.date('Y-m-d',time()).'.txt');die;
        // }

        $pingshu=gp()['number'];
        $planrealvolume=floor($pingshu/$itemo['itemctn']);

        
        $plan->addplanrealvolume($plano['planid'],$planrealvolume);

        //找到这个plan 对应的全部ps数据
        //酱紫可以用来求用了多少了，剩余多少了，还剩多少时间了
        $arr_psls=$ps->getpslsbyplanid($plano['planid']);$psls=$arr_psls['data'];

        foreach($psls as $psv){
            //计算线边倒计时
            
         //    $linespeed=$linespeed*$psv['partvolumepc'];//件/分
        	// $psremain=$psv['psalready']-$planrealvolume*$psv['partvolumepc'];
         //    $dt['psremain']=$psremain;
         //    $dt['psleavetm']=$psremain/$linespeed*60;
        	// $ps->mdf($dt,$psv['psid']);
            
            $arr_yuzhio=$yuzhi->getyuzhio($psv['f_ps_partid'],$lineo['lineid']);$yuzhio=$arr_yuzhio['data'];$linespeed=$yuzhio['yuzhispeed'];//瓶/每分钟
            $linespeed=$linespeed/$itemo['itemctn'];//箱/秒
             
            $alreadyxiang=$psv['psalready']/$psv['partvolumepc'];
            $xianbiantm=($alreadyxiang-$planrealvolume)/$linespeed;
            $dt['psleavetm']=$xianbiantm;
            $ps->mdf($dt,$psv['psid']);


        }

		
    }
    
   

}